public class Day02 {
    public static void main(String[] args) {
        Day02 day02 = new Day02();
        long k = 1;
        int i = 1;
        /*
            因为先算右边，再算左边，
            所以先将 i++ 的返回值是 1
            但是当算完右侧的时候 i 为 2
            此时再执行 =
            那么 i 又重新赋值为 1
         */
//        i = i++;// 1 -- i + 1 -- 赋回去 1
//        int b = 1;
//        b = ++b;// 2
//        System.out.println(i + " " + b);
//        System.out.println(day02.truncateSentence("Hello how are you Contestant", 4));
    }

    public int removeDuplicates(int[] nums) {
        int index = 0;//index 所表示的下标是已经放入的下标的最后一个
        for (int i = 1; i < nums.length; i++) {
            if(nums[index] != nums[i]) {
                nums[++index] = nums[i];
            }
        }
        return index + 1;
    }
    public String truncateSentence(String s, int k) {
        StringBuilder sb = new StringBuilder();
        String[] split = s.split("\\s+");
        int len = split.length < k ? split.length : k;
        for (int i = 0; i < len - 1; i++) {
            sb.append(split[i]).append(" ");
        }
        return sb.append(split[len - 1]).toString();
    }
}
